package com.longyiqun.android.zhihu.Data;

import com.longyiqun.android.zhihu.Object.Case;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.io.File;
import java.util.ArrayList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;


/**
 * Created by teddy on 3/24/16.
 */
public class MyGridViewData {
    public static final int SAMPLE_DATA_ITEM_COUNT = 30;

    public static ArrayList<String> getData() {
        final ArrayList<String> data = new ArrayList<String>(SAMPLE_DATA_ITEM_COUNT);

        for (int i = 0; i < SAMPLE_DATA_ITEM_COUNT; i++) {
            data.add("Item #");
        }

        return data;
    }

    public static ArrayList<Case> getCases() {
        ArrayList<Case> cases = new ArrayList<Case>();
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();



            File fXmlFile = new File("assets/cases.xml");
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(fXmlFile);
            doc.getDocumentElement().normalize();
            NodeList animalNodes = doc.getElementsByTagName("animal");


            DocumentBuilder builder = factory.newDocumentBuilder();
            Document dom = builder.parse("assets/cases.xml");
            Element root = dom.getDocumentElement();
            NodeList items = root.getElementsByTagName("case");

            return cases;
        }
        catch (Exception ex) {
            System.out.println(ex.getMessage());
            return null;
        }
    }
}
